<?php

class Home_DashboardController extends BaseController
{

	public function __construct()
	{
		parent::__construct();
	}

	public function indexAction() 
	{		
	    return $this->forward('dashboard/panel/show');
	}	
	
	public function showAction() 
	{
		$this->renderView('home/dashboard/show');
	}
	
	public function formViewAction()
	{
		
		$this->renderView('home/dashboard/form');
	}

	public function tableViewAction()
	{
		$this->renderView('home/dashboard/table');
	}

	public function blankPageAction()
	{
		$this->renderView('home/dashboard/blank');
	}

	public function permissionFormAction()
	{
		$acls = new Base_ModuleAcls(__APP_PATH.'/config/acls.php');
		
		
		$this->renderView('home/dashboard/permission');
	}	
	
	public function renderLeftNavAction()
	{
		$arrPageMenus = array();
		$objPageConf = new Page_Configure();
		$rsPages = $objPageConf->getRowset("data <> ''");

		$objPageCat = new Page_Category();
		
		foreach ($rsPages as $rowPage)
		{
			$key = 'page/content/'.$rowPage['code'];
			if ($this->oAuth->hasPermission('access',$key))
			{
				$arrTemp = array();
				$arrTemp['name'] = $rowPage['name'];
				$arrTemp['icon'] = "icon-file-alt";
				
				$data = unserialize($rowPage['data']);
				
// 				$arrSub = array();
// 				$rsCat = $objPageCat->getRowset('page_id = ?', array($rowPage['id']));
// 				if (count($rsCat))
				if ($data['use_category'] == 1) 
				{
					$arrSub[] = array("icon"=>"icon-file-alt", "name" => "Category","link" => "page/category/list/".$rowPage['code']);
				}
				$arrSub[] = array("icon"=>"icon-file-alt", "name" => "List","link" => "page/content/list/".$rowPage['code']);
				$arrSub[] = array("icon"=>"icon-file-alt","name" => "Add new","link" => "page/content/add/".$rowPage['code']);
				$arrTemp['sub_menus'] = $arrSub;
				
				$arrPageMenus[$key] = $arrTemp;
			}
		}
		
		$menuInfo = array();
		$menus = require_once(__APP_PATH.'/config/left_menus.php');
		
		foreach ($menus as $key => $menu)
		{
			$arrTemp = array();
			$arrTemp['name'] = $menu['name'];
			$arrTemp['icon'] = $menu['icon'];
			
			foreach ($menu['sub_menus'] as $sub_menu)
			{
				if ($this->oAuth->hasPermission('access',$sub_menu['key']))
				{
					$arrTemp['sub_menus'][] = $sub_menu;
				}
			}
			
			if (!empty($arrTemp['sub_menus']))
			{
				$menuInfo[$key] = $arrTemp;
			}
		}

		$menuInfo = array_merge($arrPageMenus,$menuInfo);
		
		$this->oView->menuInfo = $menuInfo;
		return $this->oView->fetch('home/dashboard/nav');
	}	

}
